package com.ojoin.trade.supplyloan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.supplyloan_core.web.dao.TbSlLoanStatTotalDao;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatTotal;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatTotalVo;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatTotalVoCompare;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-10-22
 * Time: 上午11:42
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TbSlLoanStatTotalDaoImpl extends BaseDaoImpl<TbSlLoanStatTotal> implements TbSlLoanStatTotalDao {
   

   

	@Override
	public List<TbSlLoanStatTotalVo> queryTbSlLoanStatTotalByJoinidAndTime(
			int joinuserNo, String time) throws BusinessException {
		
		 
		String mapMethodName="selectTbSlLoanStatTotalByJoinidAndTime";
        Map<String,Object> paramap=new HashMap<String, Object>();
        paramap.put("id_of_tb_merchant_user",joinuserNo);    
        paramap.put("stat_end_date",time);    
               
    	List<TbSlLoanStatTotalVo> list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),paramap);
            
		return list;
	}
 

	@Override
	public void deleteTbSlLoanTotalByPlatformUserIDAndDate(int platformUserId,
			String statDate) throws BusinessException {
		HashMap<String,Object> map=new HashMap<String, Object>();
        String methodname="deleteTbSlLoanTotalByPlatformUserIDAndDate";
        map.put("platformUserId",platformUserId);
        map.put("statDate",statDate);
        try {
            this.sqlSessionTemplate.delete(getSqlName(methodname),
                    map);
        } catch (Exception e) {
            throw new DaoException(String.format("删除商户电商平台总统计结果情况信息表出错->出错！语句：%s",
                    getSqlName(methodname)), e);
        }
	}

    @Override
    public List<TbSlLoanStatTotalVo> queryLoanTotalByJoinidandPlatform(int idOfTbMerchantUser, int idOfPlatformUser,Pageable page) throws BusinessException {
        String mapMethodName="selectByJoinidandPlatform";
        Map<String,Object> paramap=new HashMap<String, Object>();
        paramap.put("idOfTbMerchantUser",idOfTbMerchantUser);
        paramap.put("idOfPlatformUser",idOfPlatformUser);

        List<TbSlLoanStatTotalVo> list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),paramap,getPageBounds(page));

        return list;
    }
 
	@Override
	public List<TbSlLoanStatTotalVo> queryByPlatformAndMerchantUserIDAndDate(
			Map<String, Object> paramap) throws BusinessException {
		String mapMethodName="selectByPlatformAndMerchantUserIDAndDate";

    	List<TbSlLoanStatTotalVo> list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),paramap);
             
		return list; 
	}

	@Override
	public List<TbSlLoanStatTotalVoCompare> queryCompareByPlatformAndMerchantUserIDAndDate(
			Map<String, Object> paramap, Pageable page) {
		 
		String mapMethodName="selectCompareResultMapByPlatformAndMerchantUserIDAndDate";
		   
         
    	List<TbSlLoanStatTotalVoCompare> list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName),paramap,this.getPageBounds(page));
             
		return list; 
	}
 
	@Override
	public TbSlLoanStatTotal queryByPlateIdAndTime(String plateId, String time)
			throws BusinessException {
		String  mapMethodName= "selectByMap";
		Map<String, Object> paramap = new HashMap<String, Object>();
		paramap.put("platformUserId", plateId);
		paramap.put("rowCreateTime", time);
		
		return this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName), paramap);
	}


	@Override 
	public String getLastInsertTime(int platformAccountId) {
		return sqlSessionTemplate.selectOne(getSqlName("selectLastInsertTime"), platformAccountId);
	}
}
